package com.hzlj.position.config.common.dto.operatorActivation;


import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.fz.common.dict.annotation.Dict;
import com.hzlj.position.config.common.enums.OperatorActivationStatus;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * 定位-运营商开通(OperatorActivation)查询结果返回DTO
 *
 * @author lifh
 * @date 2023-08-17 18:16:09
 */
@Data
@ToString
@Accessors(chain = true)
public class OperatorActivationQueryResultDTO {
    private final static long oneDaySeconds = 24 * 60 * 60L;
    /**
     * 主键
     */
    private String id;
    /**
     * 运营商配置Id
     */
    private String operatorConfigId;
    /**
     * 矫正ID(jz_jbxx)
     */
    private String jzId;
    /**
     * 姓名
     */
    private String xm;
    /**
     * 手机号
     */
    private String sjh;
    /**
     * 机构code
     */
    private String jgCode;
    /**
     * 机构名称
     */
    private String jgMc;
    /**
     * 定位渠道,dict-LOCATE_CHANNEL
     */
    @Dict("LOCATE_CHANNEL")
    private String channel;
    /**
     * 定位渠道,dict-LOCATE_CHANNEL(文本)
     */
    private String channelText;
    /**
     * 开通状态,dict-OPERATOR_ACTIVATION
     */
    @Dict("OPERATOR_ACTIVATION")
    private String activation;
    /**
     * 开通状态,dict-OPERATOR_ACTIVATION(文本)
     */
    private String activationText;
    /**
     * 开通时间
     */
    private Date activationTime;
    /**
     * 取消时间
     */
    private Date deactivateTime;
    /**
     * 累计开通秒数
     */
    private Long activationSeconds;
    /**
     * 开通取消参数,json-OperatorActivationExtDTO
     */
    private OperatorActivationExtDTO ext;

    /**
     * 获取秒数
     * 1、如果是初始化、返回0
     * 2、如果是激活状态,则是 当前时间-激活时间+seconds
     * 3、如果是取消状态,则是seconds
     */
    public Long getActivationSeconds() {
        if (OperatorActivationStatus.isInit(this.getActivation())
                || OperatorActivationStatus.isDeactivate(this.getActivation())) {
            return this.activationSeconds;
        }

        long between = DateUtil.between(
                DateUtil.beginOfDay(activationTime),
                DateUtil.beginOfDay(new Date()),
                DateUnit.SECOND
        );
        return between + activationSeconds;
    }


    /**
     * 计费的days
     */
    public Long getActivationDays() {
        if (OperatorActivationStatus.isInit(this.getActivation())) {
            return 0L;
        }
        return (getActivationSeconds() / oneDaySeconds) + 1;
    }
}
